import React from 'react';
import { Route } from 'react-router-dom';
import { getToken } from '../utils/storage';

// 新建组件 为鉴权路由组件  提取path 和component属性
export default function AuthRoute (props) {

    const { path, component: Comp } = props;
    return (
      <Route
      path={path}
      render={(props) => {
        if (getToken()) {
          return <Comp {...props}></Comp>;
        } else {
          props.history.push('/login');
        }
      }}
    ></Route>
    );
  

}
